package com.jsh.erp.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.dto.TodoTaskDto;
import com.jsh.erp.datasource.entities.Account;
import com.jsh.erp.datasource.entities.MsgEx;
import com.jsh.erp.datasource.entities.TodoTask;
import com.jsh.erp.datasource.vo.AccountVo4InOutList;
import com.jsh.erp.datasource.vo.AccountVo4List;
import com.jsh.erp.datasource.vo.TodoTaskVo4List;
import com.jsh.erp.service.account.AccountService;
import com.jsh.erp.service.systemConfig.SystemConfigService;
import com.jsh.erp.service.todoTask.TodoTaskService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import com.jsh.erp.utils.Response;
import com.jsh.erp.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;

/**
 * @author GongeN
 */
@RestController
@RequestMapping(value = "/todoTask")
@Api(tags = {"我的待办"})
public class TodoTaskController {
    private Logger logger = LoggerFactory.getLogger(TodoTaskController.class);

    @Resource
    private TodoTaskService todoTaskService;

    /**
     * 根据当前登录用户id查询对应的 待办任务->（进行提醒使用）
     * @return
     */
    @GetMapping("/getBacklogById")
    public BaseResponseInfo getBacklogById(HttpServletRequest request){
        BaseResponseInfo res = new BaseResponseInfo();
        try {
            List<TodoTask> list = todoTaskService.getBacklogById(request);
            res.code = 200;
            res.data = list;
        } catch(Exception e){
            logger.error(e.getMessage(), e);
            res.code = 500;
            res.data = "获取数据失败";
        }
        return res;
    }

//    @PostMapping("/update")
//    public BaseResponseInfo update(@RequestBody TodoTask todoTask){
//        int result = todoTaskService.(todoTask);
//        BaseResponseInfo info = new BaseResponseInfo();
//        info.code=result>0?200:500;
//        return info;
//    }

    /**
     * 工作台-待办任务=》任务处理审批。
     * @param todoTask
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping("/taskAudit")
    public Response taskAudit(@RequestBody TodoTaskDto todoTask, HttpServletRequest request) throws Exception {
        todoTaskService.taskAuditFlow(todoTask,request);
        return Response.success();
    }

    /**
     * 任务完成！
     * @return
     */
    @PostMapping("/taskFinished")
    public Response taskFinished(@RequestParam("id")Long id){
        todoTaskService.taskFinished(id);
        return Response.success();
    }
}
